#build on window
# mkdir build
# cd build
# cmake .. -DCMAKE_BUILD_TYPE=Debug -G"Unix Makefiles"
# cmake .. -DCMAKE_BUILD_TYPE=Release -G"Unix Makefiles"

#
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3 -O0 -Wmissing-declarations -Werror -Wall")

# project
cmake_minimum_required(VERSION 2.8.8)
set(TARGET Vclient)
project(${TARGET})

option(USE_LOG4C "enable use log4c" OFF)

IF(WIN32)
    # windows platform
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mwindows")
    set(USE_LOG4C ON)
ELSEIF(APPLE)
    # MAC platform
ELSE()
    # Linux platform
    set(USE_WEBKIT ON)
    set(USE_LOG4C OFF)
ENDIF()

# Include our extra modules
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)

include(FindPkgConfig)
pkg_check_modules(SPICE_CLIENT_GLIB REQUIRED spice-client-glib-2.0)
pkg_check_modules(SPICE_CLIENT_GTK  REQUIRED spice-client-gtk-3.0)
pkg_check_modules(JSON_LIB          REQUIRED json-glib-1.0)
pkg_check_modules(OPENSSL           REQUIRED openssl)
pkg_check_modules(LIBCURL           REQUIRED libcurl)
pkg_check_modules(USB_REDIR         REQUIRED libusb-1.0)

# check webkit2gtk-4.0
pkg_check_modules(WEBKIT QUIET webkit2gtk-4.0)
if(WEBKIT_FOUND)
    add_definitions(-DHAVE_WEBKIT2GTK)
elseif(USE_WEBKIT)
    message(FATAL_ERROR " not found webkit2gtk-4.0")
endif()

if(USE_LOG4C)
    # check log4c
    # on fedora, 'pkg_check_modules' is ok
    # on debian, no 'liblog4c.pc' , pkg_check_modules is not work
    pkg_check_modules(LOG4C QUIET log4c)
    if(NOT LOG4C_FOUND)
        find_package(Log4c REQUIRED)
    endif()
    add_definitions(-DHAVE_LOG4C)
endif()

include_directories(
    .
    ${SPICE_CLIENT_GLIB_INCLUDE_DIRS}
    ${SPICE_CLIENT_GTK_INCLUDE_DIRS}
    ${JSON_LIB_INCLUDE_DIRS}
    ${USB_REDIR_INCLUDE_DIRS}
    ${LOG4C_INCLUDE_DIRS}
    ${OPENSSL_INCLUDE_DIRS}
    ${LIBCURL_INCLUDE_DIRS}
    ${WEBKIT_INCLUDE_DIRS}
    )

set(COMMON_LIBS
    ${SPICE_CLIENT_GLIB_LIBRARIES}
    ${SPICE_CLIENT_GTK_LIBRARIES}
    ${JSON_LIB_LIBRARIES}
    ${USB_REDIR_LIBRARIES}
    ${LOG4C_LIBRARIES}
    ${OPENSSL_LIBRARIES}
    ${LIBCURL_LIBRARIES}
    ${WEBKIT_LIBRARIES}
    )

ADD_SUBDIRECTORY(tools)


